#include <bits/stdc++.h>
using namespace std;

class Solution
{
public:
    int main()
    {
        int len, m;
        cin >> len >> m;
        vector<int> trees(len + 1, 1);
        vector<vector<int>> intervals;
        for (int i = 0; i < m; ++i)
        {
            int start, end;
            cin >> start >> end;
            intervals.push_back({start, end});
        }
        sort(intervals.begin(), intervals.end());
        int lastEnd = -1;
        for (auto &interval : intervals)
        {
            for (int i = max(lastEnd, interval[0]); i <= interval[1]; ++i)
            {
                trees[i] = 0;
            }
        }
        cout << accumulate(trees.begin(), trees.end(), 0);
        return 0;
    }
};

#ifndef __LOCAL_TEST__
int main()
{
    return Solution().main();
}
#endif